home *** CD-ROM | disk | FTP | other *** search
/ MaxiMac 2000 December / MaxiMac 109.iso / Macworld on CD n°109 / Applications (Mac OS X PB) / MacOSX ScreenSavers / Source Code / Pipes / buildlwo.c next >
Encoding:
C/C++ Source or Header  |  2000-10-02  |  1.8 KB  |  92 lines  |  [????/????]

  1.  
  2. #if !defined( lint ) && !defined( SABER )
  3. static const char sccsid[] = "@(#)buildlwo.c    4.02 97/04/20 xlockmore";
  4.  
  5. #endif
  6.  
  7. /*-
  8.  * buildlwo.c: Lightwave Object Display List Builder for OpenGL
  9.  *
  10.  * This module can be called by any GL mode wishing to use
  11.  * objects created in NewTek's Lightwave 3D.  The objects must
  12.  * first be converted to C source with my converter "lw2ogl".
  13.  * If other people are interested in this, I will put up a
  14.  * web page for it at http://www.netaxs.com/~emackey/lw2ogl/
  15.  *
  16.  * by Ed Mackey, 4/19/97
  17.  *
  18.  */
  19.  
  20.  
  21. #include <OpenGL/gl.h>
  22. #include <OpenGL/glu.h>
  23. #include "buildlwo.h"
  24.  
  25. GLuint
  26. BuildLWO(int wireframe, struct lwo *object)
  27. {
  28.     GLuint      dl_num;
  29.     GLfloat    *pnts, *normals, three[3], *grab;
  30.     unsigned short int *pols;
  31.     int         p, num_pnts = 0;
  32.  
  33.     dl_num = glGenLists(1);
  34.     if (!dl_num)
  35.         return (0);
  36.  
  37.     pnts = object->pnts;
  38.     normals = object->normals;
  39.     pols = object->pols;
  40.  
  41.     glNewList(dl_num, GL_COMPILE);
  42.  
  43.     if (!pols) {
  44.         num_pnts = object->num_pnts;
  45.         glBegin(GL_POINTS);
  46.         for (p = 0; p < num_pnts; ++p) {
  47.             three[0] = *(pnts++);
  48.             three[1] = *(pnts++);
  49.             three[2] = *(pnts++);
  50.             glVertex3fv(three);
  51.         }
  52.         glEnd();
  53.     } else
  54.         for (;;) {
  55.             if (num_pnts <= 0) {
  56.                 num_pnts = *pols + 2;
  57.                 if (num_pnts < 3)
  58.                     break;
  59.                 if (num_pnts == 3) {
  60.                     glBegin(GL_POINTS);
  61.                 } else if (num_pnts == 4) {
  62.                     glBegin(GL_LINES);
  63.                 } else {
  64.                     three[0] = *(normals++);
  65.                     three[1] = *(normals++);
  66.                     three[2] = *(normals++);
  67.                     glNormal3fv(three);
  68.                     if (wireframe)
  69.                         glBegin(GL_LINE_LOOP);
  70.                     else
  71.                         glBegin(GL_POLYGON);
  72.                 }
  73.             } else if (num_pnts == 1) {
  74.                 glEnd();
  75.             } else {
  76.                 grab = pnts + ((int) (*pols) * 3);
  77.                 three[0] = *(grab++);
  78.                 three[1] = *(grab++);
  79.                 three[2] = *(grab++);
  80.                 glVertex3fv(three);
  81.             }
  82.             --num_pnts;
  83.             ++pols;
  84.         }
  85.  
  86.     glEndList();
  87.  
  88.     return (dl_num);
  89. }
  90.  
  91. /* End of buildlwo.c */
  92.